$(function () {
    var week = $("select[name='week'] option:selected").val();

    select_time(week);
});

$("select[name='week']").change(function () {

    select_time($(this).val());

});

function select_time(week = 0) {

    var form = new FormData();

    form.append("week", week);

    var time = '<option value="">請選擇時間段</option>';

    var loadding_index = layer.load(1, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });

    $.ajax({
        type: 'POST',
        url: '/class_base_time',
        dataType: "json",   //返回格式为json
        data: form,
        processData: false,
        contentType: false,
        success: function (result) {

            layer.close(loadding_index);

            var base_time_result = result.data.base_time;
            var base_time_result = result.data.base_time;

            for (var i = 0; i < base_time_result.length; i++) {
                time += '<option value="' + base_time_result[i].id + '" duration="'+base_time_result[i].duration+'" ';
                if (base_time_result[i].id == base_time_id) time += 'selected';
                time += '>' + base_time_result[i].class_time + '</option>';
            }

            $("select[name='base_time']").html(time);

            // var base_time_duration = $("select[name='base_time'] option:checked").attr('duration');
            //
            // if(base_time_duration != ''){
            //     $("input[name='class_duration']").val(base_time_duration);
            // }else{
            //     $("input[name='class_duration']").val('');
            // }

        }
    });
}

